<?php
include("startsess.php");
if($log){
    if(isset($_POST['do_edit'])) $doc = getDocInfoFullSent($_POST['edoc_id'],$_POST['depart_id']);
    else $doc = getDocInfoFullSent($_GET['edoc_id'],$_GET['depart_id']);
    if(canEditDoc($doc,$_GET['depart_id']) && !isset($_POST['do_edit'])){
?>

<form action="edit_doc_sent.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="depart_id" value="<?php echo $_GET['depart_id']; ?>">
<input type="hidden" name="edoc_id" value="<?php echo $_GET['edoc_id']; ?>">
<input type="hidden" name="sent_no" value="<?php echo $doc['sent_no']; ?>">
<input type="hidden" name="sent_date" value="<?php echo $doc['sent_date']; ?>">
<input type="hidden" name="sent_time" value="<?php echo $doc['sent_time']; ?>">
<input type="hidden" name="edit_typesent" value="hard">
<table cellpadding="5" cellspacing="0" border="0">
<tr><td>หน่วยงานส่ง</td><td>:</td><td><?php echo $doc['depart_name_sent']; ?></td></tr>
<tr><td>วันที่ส่ง</td><td>:</td><td class="topic"><?php echo dateThDeco($doc['sent_date']); ?></td></tr>
<tr><td>เวลาส่ง</td><td>:</td><td class="topic"><?php echo $doc['sent_time']; ?></td></tr>
<tr><td>เลขที่หนังสือ</td><td>:</td><td class="topic"><?php echo $doc['doc_no']; ?></td></tr>
<tr><td>วันที่หนังสือ</td><td>:</td><td><input value="<?php echo dateThDeco($doc['doc_date']); ?>" type="text" name="doc_date" size="50" maxlength="450"></td></tr>
<tr><td>ชั้นความลับ</td><td>:</td><td>
<optgroup label="secret">
<?php secretGroup($doc['secret']); ?>
</optgroup>
</td></tr>
<tr><td>ความเร่งด่วน</td><td>:</td><td>
<optgroup label="rapid">
<?php rapidGroup($doc['secret']); ?>
</optgroup>
</td></tr>
<tr><td>ประเภทหนังสือ</td><td>:</td><td>
<?php
	list_doctypesent_option($_GET['depart_id'],$doc['edoc_typesent_id']); 
?>
</td></tr>
<tr><td colspan="2"> </td><td><input type="text" name="doctype_add" size="50" maxlength="450"></td></tr>
<tr><td>เรียน</td><td>:</td><td><input value="<?php echo $doc['reciever']; ?>" type="text" name="reciever" size="50" maxlength="450"></td></tr>
<tr><td>เรื่อง</td><td>:</td><td><input value="<?php echo $doc['headline']; ?>" type="text" name="headline" size="50" maxlength="450"></td></tr>
<tr valign="top"><td>ผู้ส่ง</td><td>:</td><td><textarea name="sender" rows="3" cols="50"><?php echo nl2br(htmlspecialchars($doc['sender'])); ?></textarea></td></tr>
<tr valign="top"><td>การปฏิบัติ</td><td>:</td><td><textarea name="comment" rows="3" cols="50"><?php echo nl2br(htmlspecialchars($doc['comment'])); ?></textarea></td></tr>
<tr><td>ไฟล์ PDF</td><td>:</td><td><input type="file" name="pdf" size="50"></td></tr>
<tr><td colspan="2"> </td><td><input type="submit" name="do_edit" value=" แก้ไขหนังสือส่ง "></td></tr>
</table>
</form>

<?php
    }else if(canEditDoc($doc,$_POST['depart_id']) && ($_POST['edit_typesent']=="hard") && isset($_POST['do_edit'])){

        $r = editDocHardSent($_POST['edoc_id'],$_POST['sent_no'],$_POST['sent_date'],$_POST['sent_time'],$_POST['doc_date'],$_POST['secret'],$_POST['rapid'],$_POST['doctypesent'],$_POST['hdepart'],$_POST['reciever'],$_POST['headline'],$_POST['sender'],$_POST['comment'],$HTTP_POST_FILES['pdf'],$_POST['depart_id']);
		if($r==-3) echo "<span class=\"err\">ERROR : ไม่สามารถแก้ไขหนังสือส่งได้</span><br /><br />";
		else if($r==-4) echo "<span class=\"err\">ERROR : ไม่สามารถแก้ไขประเภทหนังสือส่งได้</span><br /><br />";
		else echo "แก้ไขหนังสือส่งเลขที่ <span class=\"topic\">".$_POST['doc_no']."</span> เรียบร้อยแล้ว<br /><br />";
		
		$doc = getDocInfoSent($_POST['edoc_id'],$_POST['depart_id']);
?>
<table cellpadding="5" cellspacing="0" border="0">
<tr><td>หน่วยงานส่ง</td><td>:</td><td><?php echo $doc['depart_name_sent']; ?></td></tr>
<tr><td>วันที่ส่ง</td><td>:</td><td class="topic"><?php echo dateThDeco($doc['sent_date']); ?></td></tr>
<tr><td>เวลาส่ง</td><td>:</td><td class="topic"><?php echo $doc['sent_time']; ?></td></tr>
<tr><td>เลขที่หนังสือ</td><td>:</td><td><?php echo $doc['doc_no']; ?></td></tr>
<tr><td>วันที่หนังสือ</td><td>:</td><td><?php echo dateThDeco($doc['doc_date']); ?></td></tr>
<tr><td>ชั้นความลับ</td><td>:</td><td>
<?php echo shSecret($doc['secret']); ?>
</td></tr>
<tr><td>ความเร่งด่วน</td><td>:</td><td>
<?php echo shRapid($doc['secret']); ?>
</td></tr>
<tr><td>ประเภทหนังสือส่ง</td><td>:</td><td>
<?php echo $doc['edoc_typesent_name']; ?>
</td></tr>
<tr><td>จากหน่วยงาน</td><td>:</td><td>
<?php echo shDepartSendFast($doc['depart_send_id'],$doc['depart_name_send'],$doc['depart_send_name_out']); ?>
</td></tr>
<tr><td>เรียน</td><td>:</td><td><?php echo $doc['reciever']; ?></td></tr>
<tr><td>เรื่อง</td><td>:</td><td><?php echo $doc['headline']; ?></td></tr>
<tr valign="top"><td>ผู้ส่ง</td><td>:</td><td><?php echo nl2br(htmlspecialchars($doc['sender'])); ?></td></tr>
<tr valign="top"><td>การปฏิบัติ</td><td>:</td><td><?php echo nl2br(htmlspecialchars($doc['comment'])); ?></td></tr>
<tr><td>ไฟล์ PDF</td><td>:</td><td><?php echo PDFnameLink($doc['pdf_name'],$doc['edoc_id']); ?></td></tr>
</table>
<?php    
    }else{
?>    
<span class="err">You can not do this function ...<br /></span><br />
<?php    
    }
}else{
	echo "Log in fail ...<br /><br />";
}
include("ft.php");
?>
